<?php
namespace Admin\Controller;
use Think\Controller;
class DBController extends CommonController {

public function index(){
        $M = M();
        $tabs = $M->query('SHOW TABLE STATUS');
        $total = 0;
        foreach ($tabs as $k => $v) {
            $tabs[$k]['size'] = $this->byteFormat($v['Data_length'] + $v['Index_length']);
            $total+=$v['Data_length'] + $v['Index_length'];
        }
        //echo __APP__."/Public/data/";
   // echo  $this->export($tablename="");
 //  echo $this->restore("./Public/backup/20130704091642_tao_group_v1.sql");
        $this->assign("list", $tabs);
        $this->assign("total", $this->byteFormat($total ));
        $this->assign("tables", count($tabs));
		$this->assign("main_title", L('db_backup'));
        $this->display();
    }
 
  public function export(){
  $db = new \Common\Common\DbManage ( C('DB_HOST'), C('DB_USER'), C('DB_PWD'), C('DB_NAME'), 'utf8' );
  $db->backup('',C('DB_BACKUP'),C('DB_BACKUP_SIZE'));
  }
  
  /**
  +----------------------------------------------------------
  * 功能：计算文件大小
  +----------------------------------------------------------
  * @param int $bytes
  +----------------------------------------------------------
  * @return string 转换后的字符串
  +----------------------------------------------------------
  */
  private function byteFormat($bytes) {
     $sizetext = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
     return round($bytes / pow(1024, ($i = floor(log($bytes, 1024)))), 2) . $sizetext[$i];
  }
  
 }
    
